<?php
class cartoon_model_adv extends cartoon_model_bmodel {
	public function __construct(){
		parent::__construct();
		
		$this->table = 'cartoon_advs';	//adv表
	}
	
	/**
	 * 添加adv
	 *
	 * @param unknown_type $args
	 */
	public function add($args){
		return $this->db->insert($this->table,$args);
	}
	
	/**
 	 * 删除
 	 *
 	 * @param unknown_type $id
 	 */
 	public function remove($id){
 		if(!$id) return false;
 		$id = is_array($id)?implode(',',$id):$id;
 		return $this->db->query("DELETE FROM $this->table WHERE adv_id IN($id)");
 	}
 	
 	/**
 	 * 修改状态
 	 *
 	 * @param unknown_type $id
 	 * @param unknown_type $flag
 	 * @return unknown
 	 */
 	public function setFlag($id,$flag){
 		$id = is_array($id)?implode($id):$id;
 		
 		$sql = "UPDATE $this->table SET adv_flag = $flag WHERE adv_id IN ($id) ";
 		
 		return $this->db->query($sql);
 	}
 	
 	/**
 	 * 分页获取列表
 	 *
 	 * @param unknown_type $page
 	 * @param unknown_type $pageSize
 	 */
 	public function  getListPages($args = array('pos'=>'','flag'=>''),$page = 1,$pageSize = 30){
 		$sql = "SELECT * FROM $this->table WHERE 1 ";
 		$where = '';
 		if($args['pos']) $where .= ' AND adv_position = '.$args['pos'];
 		if($args['flag']) $where .=' AND adv_flag = '.$args['flag'];
 		$sql.="  ORDER BY adv_id DESC ";
 		return $this->db->selectPage($sql,array(),$page,$pageSize);
 	}
 	
 	/**
 	 * 获取最新的$num条记录
 	 *
 	 * @param unknown_type $num
 	 */
 	public function getListNum($type = null,$num = 4){
 		$sql = "SELECT * FROM $this->table ";
 		if($type){
 			$sql.=" WHERE adv_position = $type ";
 		}
 		$sql.= " ORDER BY adv_id DESC LIMIT $num ";
 		return $this->db->fetchAll($sql);
 	}
}